<?php
include_once('../simple_html_dom.php');

function scraping_barnard() {
    // create HTML DOM
    $date = '03_10_2013';
	$meal = 'breakfast';
	$location = 'Hewitt';
	switch($meal) {
		case 'breakfast':
		  $mealID = 1;
		  break;
		case 'lunch':
		  $mealID = 16;
		  break;
		case 'brunch':
		  $mealID = 88;
		  break;
		case 'dinner':
		  $mealID = 17;
		  break;
		default:
		  $mealID = 1;
		  break;
	}
	switch($location) {
	    case 'Hewitt':
		  $realLocation = 'HewittDiningHallMenu';
		  $locationID = 'Hewitt%20Dining%20Hall%20Menu';
		  break;
		case 'Diana':
		  $realLocation = 'DianaCenterCafeMenu';
		  $locationID = 'DianaCenterCafeMenu';
		  break;
	}
	$html = file_get_html('http://www.campusdish.com/en-US/CSE/Barnard/Locations/HewittDiningHallMenu.htm?LocationName=Hewitt%20Dining%20Hall%20Menu&MealID=16&OrgID=189097&Date=3_10_2013&ShowPrice=False&ShowNutrition=True');
	//$html = file_get_html('http://www.campusdish.com/en-US/CSE/Barnard/Locations/HewittDiningHallMenu.htm?LocationName=Hewitt%20Dining%20Hall%20Menu&MealID='.$mealID.'&OrgID=0&Date='.$date.'&ShowPrice=False&ShowNutrition=True');
	
	echo '<pre>';
	print($html);
	echo '</pre>';
	foreach($html->find('a.recipeLink') as $a) {
		$item['title'] = trim($a->plaintext);
		$ret[] = $item;
	}
    /*// get article block
    foreach($html->find('table[border^=1]') as $section) {
        foreach($section->find('td.menuBorder', 0) as $day) {
			print_r($day);
			$item['title'] = trim($day->find('a.recipeLink', 0)->plaintext); // get title
            $ret[] = $item;
		}
    }
    */
    // clean up memory
    $html->clear();
    unset($html);
	//$ret = '';
    return $ret;
}

// -----------------------------------------------------------------------------
// test it!
$ret = scraping_barnard();

foreach($ret as $v) {
    echo $v['title'].'<br>';
}
?>